<?php

// Get WordPress table prefix
if (!function_exists('get_wp_table_prefix')) {
    function get_wp_table_prefix() {
        // First check environment variable for multisite support
        $env_prefix = getenv('FALCON5_TABLE_PREFIX');
        if ($env_prefix) {
            return $env_prefix;
        }
        
        // If running in WordPress environment
        if (defined('ABSPATH') && function_exists('get_option')) {
            global $wpdb;
            return $wpdb->prefix;
        }
        
        // If not in WordPress environment, use DB_PREFIX constant or default value
        return defined('DB_PREFIX') ? DB_PREFIX : 'wp_';
    }
}

// Get table prefix
$table_prefix = get_wp_table_prefix();

return
    [
        'paths' => [
            'migrations' => '%%PHINX_CONFIG_DIR%%/db/migrations',
            'seeds' => '%%PHINX_CONFIG_DIR%%/db/seeds'
        ],
        'environments' => [
            'default_migration_table' => $table_prefix . 'phinxlog',
            'default_environment' => 'production',
            'production' => [
                'adapter' => 'mysql',
                'host' => defined('DB_HOST') ? DB_HOST : 'mysql',
                'name' => defined('DB_NAME') ? DB_NAME : 'wordpress',
                'user' => defined('DB_USER') ? DB_USER : 'root',
                'pass' => defined('DB_PASSWORD') ? DB_PASSWORD : '123456',
                'port' => '3306',
                'charset' => 'utf8',
                'table_prefix' => $table_prefix,
            ],
        ],
        'version_order' => 'creation'
    ];
